<html><head><title></title>	
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="img/cunity.ico">
<?php
	$langs = (array_key_exists('HTTP_ACCEPT_LANGUAGE' , $_SERVER) ? explode("," , $_SERVER['HTTP_ACCEPT_LANGUAGE']) :  array());
	$locale = 'en';
	foreach($langs as $lang)
	{
		if(strpos(trim($lang), 'de')==0)
		{
			$locale = 'de';
			break;
		}		
	}
	//$locale = 'de';# TODO: EN VERSION
	$required = ($locale == 'en'?
	"Javascript and Flash Player Version 10<br/>
				are required to visit this Site!" :
	"Javascript und der Flash Player ab Version 10<br/>
				müssen aktiviert sein um diese Seite zu sehen !");
	$alternativeContent = <<< ALT
	<table height="100%">
		<tr>
			<td>
				$required
			</td>
		</tr>
	</table>
ALT;
	#---------- - LOAD HOME.XML AND PARSE BGGRADIENT COLORS
	$bgGradients = array();
	$start = $end = 'fff';
	$main = isset($_GET['main']) ? $_GET['main'] : "site/main.xml";
	if (file_exists($main))
	{
		$xml = simplexml_load_file($main);
		echo ("<!--");
		$xml = $xml->Def;
		#print_r($xml);
		echo("-->");
		foreach($xml->BackGround as $bG)
		{
			#error_log($bG['id'] . '->' . $bG['colors']);
			$id = $bG['id'];
			$bgGradients["$id"] = str_replace('0x', '', explode(',', $bG['colors']));
			//$bgGradients[$bG['id']] = str_replace('0x', '', explode(',', $bG['colors']));
		}
	}
	echo '<!--';
	echo ('site/main.xml'.file_exists('site/main.xml'));
	print_r($bgGradients);
	echo '-->';
	$all = array_keys($bgGradients);
	$bgUse = isset($_COOKIE['BackGround']) ? $_COOKIE['BackGround'] : $all[0];
	$start = $bgGradients[$bgUse][0];
	$end = $bgGradients[$bgUse][1];
	error_log("$start -> $end");
	
	require "inc/latLong.php";
	$location = getLatLong();
	if(is_array($location))
	{
		$latitude = $location[0];
		$longitude = $location[1];
	}
	else $latitude = $longitude = 0;
	
	require('site.php');
	//Site::$instance->init("site/$locale/");
	Site::$instance->init("site/");
	$siteMap = Site::$siteMap;

	#$movie ="swf/cUnity.swf?content=$content&random=".rand();
	$movie ="swf/cUnity.swf?random=".rand();

	$page = <<< PAGE
<script type='text/javascript' src='js/debugWin.js'></script>	
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/swfaddress.js"></script> 
<script type="text/javascript">
	SWFAddress.setStrict(false); 
	var flashvars = {
		latitude: "$latitude",
		longitude: "$longitude",
		locale: "$locale"
	};
	var params = {
	  menu: "false",
	  allowscriptaccess : "always",
	  allowfullscreen: "true",
	  scale: "NoScale",
	  salign: "TL"
	};
	var attributes = {
	  id: "stage",
	  name: "stage",
	  style:"position:absolute;top:-2000"
	};
	
	var fn = function(){
		swfobject.embedSWF(
			"$movie", "stage", "100%", "100%", "10.0.0","swf/expressInstall.swf", flashvars, params, attributes);
		init();
	};
	swfobject.addDomLoadEvent(fn);	

</script>	

<script type='text/javascript' src='js/keyboard.js'></script>
<script type='text/javascript' src='js/easy_cookie-min.js'></script>	
<script type='text/javascript'><!--
debugging = 1;

function init(){
	//debug('init:' + EasyCookie.enabled + ' innerHeight:' + innerHeight + ' innerWidth:' + innerWidth);
	//debug(EasyCookie.keys());
	//debug(EasyCookie.all());
	initKeyboard();
	document.getElementById('stage').focus();	
}

function setStatus(s){
	window.status = s;
	//debug(s + ':' + window.status);
}


function setCookie(ob){
	for(key in ob){
		EasyCookie.set(key, ob[key]);
		//debug( key + ' set2:' + EasyCookie.set(key, ob[key]));
	}
}

function clearCookies(){
	keys = EasyCookie.keys();
	for(k=0;k<keys.length-1;k++){
		EasyCookie.remove(keys[k]);
		//debug('removed ' + k+ ' '  + keys[k] +':' + EasyCookie.remove(keys[k]));
	}
}

function layoutBg( ) {
	msie = op = false
	nav = navigator.userAgent
	if (/msie/i.test(navigator.userAgent) ) {
		msie = 1
		w = document.body.clientWidth
		h = document.body.clientHeight
		//if(debugging) debug('msie:'+w +'x' +h)
		window.onerror = null
		if(w <800) {
		resizeTo(screen.availWidth, screen.availHeight);
		moveTo(0,0);
		w = document.body.clientWidth
		h = document.body.clientHeight	
		}
	}
	else	if(innerWidth){
		w = innerWidth
		h = innerHeight
		if(w <800) {
		resizeTo(screen.availWidth, screen.availHeight);
		moveTo(0,0);
		w = innerWidth
		h = innerHeight		
		}		
	}	
	(/opera/i.test(navigator.userAgent) ) ? op = 1 : op = 0;
	if(/opera/i.test(navigator.userAgent) && parseInt(navigator.appVersion)<9){
		document.writeln(' Incompatible browser :-( Opera must be at least Version 9.0<br>');
		document.writeln('<a href="opera.com">Update Your Browser</a><br>');
		document.writeln('<a href="mozilla.org">Or Use Mozilla or Firefox and comeBack</a>');
		return		
	}
	if(typeof(w) == 'undefined'){
		document.writeln(' Incompatible browser :-(');
		document.writeln('<a href="mozilla.org">Download Mozilla or Firefox and comeBack</a>');
		return	
	}
	type = 'gradient';
	bg = document.getElementById('bG');
	switch (type){
		case 'gradient':
		bgUrl =  'inc/vgradient.php?width=1&height='+h+'&fade_from=$start&fade_to=$end';
		
		bg.style.backgroundImage = "url('"+bgUrl+"')"
		bg.style.backgroundRepeat = 'repeat-x';
		break;
	}	
}

function showStage()
{
	document.getElementById('stage').style.visibility = 'visible';
	document.getElementById('stage').style.top = '0px';
	document.getElementById('stage').style.left = '0px';
}

//--></script>

	<style>
	body{
		margin:0px;
		overflow:hidden;
		color:#ffd588;
	}
	object:focus{
		outline:none;
	}
	#siteMap{
		visibility:hidden;
		display:none;
	}
	#bG {
		position:relative;
		width:100%;
		height:100%;
	}
	</style>
</head>
<body  marginHeight='0' marginWidth='0' onload="layoutBg()">
	<div id='bG'>
		<center>
			<div id="stage">	
				$alternativeContent
			</div>
		</center>
	</div>		
	$siteMap
</body>
</html>
PAGE;
echo ($page);
?>
